package com.yunfangdata.web.controller;

import com.yunfangdata.domain.Officialstu;
import com.yunfangdata.query.OfficialstuQueryObject;
import com.yunfangdata.service.IOfficialstuService;
import com.yunfangdata.util.JsonResult;
import com.yunfangdata.util.PageResult;
import com.yunfangdata.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by 徐飞 on 2018/7/7.
 */
@Controller
@RequestMapping("officialstu")
public class OfficialstuController {

    @Autowired
    private IOfficialstuService officialstuService;


    @RequiresPermissions("officialstu:index")
    @PermissionName("正式学员首页")
    @RequestMapping("")
    public String index(){
        return "officialstu/list";
    }


    @RequiresPermissions("officialstu:list")
    @PermissionName("正式学员列表")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(OfficialstuQueryObject qo){
        return officialstuService.query(qo);
    }

    @RequiresPermissions("officialstu:save")
    @PermissionName("正式学员保存")
   @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Officialstu entity) {
        JsonResult result = new JsonResult();
        try{
            officialstuService.save(entity);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }
        return  result;
    }

    @RequiresPermissions("officialstu:update")
    @PermissionName("正式学员更新")
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(Officialstu entity) {
        JsonResult result = new JsonResult();
        try{
            officialstuService.update(entity);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("更新操作失败");
        }
        return  result;
    }
    @RequestMapping("leave")
    @ResponseBody
    public JsonResult leave(Long id) {
        JsonResult result = new JsonResult();
        try{
            officialstuService.leave(id);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("执行操作失败.");
        }
        return  result;
    }

 @RequestMapping("/selectName")
 @ResponseBody
 public List<Officialstu> selectName(){
     return officialstuService.list();
 }
}